//# sourceURL=login.js
var layer,element,form ,userid,useroldPwd;
$(function(){
	layui.use(['layer','element','form'], function(){
		  layer = layui.layer;
		  element = layui.element;
		  form = layui.form;

        //表单验证
        form.verify({ 
        	fnewPwd: function(value, item){//密码验证
      			if(validate.isBlank(value))
      			{
      				return "请输入新密码";
      			}
      			if(!validate.isLength(value,8,16))
      		    {
      		      return '密码长度应在8-16个字符之间';
      		    }
      			if(!validate.ispassword(value))
      		    {
      		      return '密码必须包含大小写字母、数字、特殊符号';
      		    }
      	  }
      	  ,fconfirmPassword: function(value, item)//确认密码验证
      	  {
      			if(validate.isBlank(value))
      			{
      				return "请输入确认密码";
      			}
      			if(!validate.equals($('#newPwd').val(),value))
      			{
      			 	return "两次密码输入不一致！";
      			}
      	  }
     });
	//修改密码提交
	form.on('submit(formDemo)', function(data){   	   
			var OldPwd=$("#oldPwd").val();
			var NewPwd =$("#newPwd").val();
			var Confirm =$("#confirm").val();
//			console.log(useroldPwd,OldPwd)
//			if(useroldPwd!=OldPwd){
//				layer.msg("旧密码填写错误", {icon: 5});
//				return false;
//			}
			var requestData = {"newPwd":NewPwd,"oldPwd":OldPwd};
			$.ajax({
		           url: "/sysUser/updatePwd.do",               //请求地址
		           type: "POST",              //请求类型
		           data:formatParam(requestData),              //请求数据
		           timeout: 200000, //请求超时时间(毫秒)
		           async: false,
		           headers: setHeader(),
		           success:function(res){         //请求成功
		        	   var index = parent.layer.getFrameIndex(window.name);
		        	   if(res.status == 200)
		  				{
		    				layer.msg(res.resultMsg, {icon: res.icon},function(){
		    					//parent.layer.close(index);
		    					window.location = "/login.html"; 
							}); 					
		  				}else{
		  					layer.msg(res.resultMsg, {icon: res.icon});
		  				}
		        	   
//		        	   layer.close(index);//关闭加载层     
	             }
	          })
	          return false; //阻止表单跳转
		})
   })  
})
